﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>管理</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/jquery.Jcrop.js"></script>
    <link href="~/Content/Script/jquery.Jcrop.css" rel="stylesheet" />
    <style>
        .switchbutton-on {
            background: #EAF2FF;
            color: #000000;
        }

        .switchbutton-off {
            background: #E1E1E1;
            color: #000000;
        }
    </style>
    <script>
        $(function () {
            var merid, boxid, boxname;
            getmer();//加载操作员管理的所有商户
            $('#btnadd').linkbutton('disable');
            $('#btnedit').linkbutton('disable');
            $('#btndell').linkbutton('disable');
            $('#SearchBtn').linkbutton('disable');
        });

        ///获取操作员下面的商户
        function getmer() {
            $.ajax({
                url: '/BoxManage/getmer',
                dataType: 'json',
                success: function (res) {
                    var data = JSON.parse(res);
                    $('#searchMer').combobox({
                        data: data,
                        valueField: 'MerID',
                        textField: 'MerName',
                        onSelect: function (record) {
                            initTable(record.MerID, "");
                            $('#btnadd').linkbutton('enable');
                            $('#btnedit').linkbutton('enable');
                            $('#btndell').linkbutton('enable');
                            $('#SearchBtn').linkbutton('enable');
                            getstat();//初始化下拉包厢状态
                        }
                    });
                }
            });
        }

        //初始化表格 获取对应商户所有包厢
        function initTable(pos, boxname) {
            merid = pos;
            $('#View').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                fitColumns: false,
                singleSelect: true,
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/BoxManage/getbox?merid=' + pos + "&name=" + boxname,
                sortName: 'BoxID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'BoxID',
                pageSize: 10,
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'BoxID', title: '包厢ID', sortable: true, hidden: true },
                    { field: 'BoxName', title: '包厢名称' },
                    {
                        field: 'BoxStat', title: '包厢状态', formatter: function (value) {
                            if (value == "0") {
                                return "未使用"
                            } else {
                                return "已使用"
                            }
                        }
                     }

                ]],
                toolbar: '#tb1'
            });
        }
        function getstat() {
            $.get("/BoxManage/ReturnIsShowData", {}, function (database) {
                var a = JSON.parse(database);
                $('#e_boxstat').combobox({
                    valueField: 'BoxStat',
                    textField: 'text',
                    data: a,
                });
            })
        }

        //修改包厢状态dialog
        function UpdateDialog() {
            var UpdateInfoID = $("#View").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#UpdateBoxDialog").dialog("open").dialog("setTitle", "修改包厢状态");
                var checkdata = $("#View").datagrid("getSelections")[0];
                if (checkdata != null) {
                    //console.log(checkdata.);
                    boxid = checkdata.BoxID;//包厢id
                    $("#e_boxname").textbox('setValue', checkdata.BoxName);  //包厢名称
                    $("#e_boxstat").combobox('setValue', checkdata.BoxStat);  //包厢状态
                }
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }
        //修改包厢状态提交fn
        function BindEditBoxClickEvent() {
            var postdata = {
                MerID: merid,
                BoxID: boxid,
                State: 1,
                BoxStat: $("#e_boxstat").combobox('getValue'),
                BoxName: $("#e_boxname").textbox('getValue'),
            };
            //使用异步实现修改派送员信息
            $.post("/BoxManage/updateBox?tag=" + 2, postdata, function (data) {
                if (data == "1") {
                    $("#UpdateBoxDialog").dialog('close');
                    $("#View").datagrid('reload');

                }
                else {
                    $.messager.alert("友情提示", "修改失败，请检查");
                }
            });
        }
        //搜索fn
        function SearchDishes() {
            boxname = $('#boxname').textbox('getValue');
            initTable(merid, boxname);
        }
    </script>
</head>
<body style="padding:0;">
    <div style="padding: 5px; background-color: #F4F4F4">
        <div>
            <a>商户：</a>
            <input id="searchMer" value="">
        </div>
    </div>

    <div>
        <table id="View" border="0"></table>
    </div>
    <div id="tb1" style="background-color: #F4F4F4">
        <div style="margin-bottom: 5px">
            <a href="#" id="btnedit" class="easyui-linkbutton" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">修改包厢状态</a>
        </div>
        <div style="margin-left: 5px;">
            <a>包厢名称：</a>
            <input id="boxname" class="easyui-textbox" style="width: 120px" />
            <a id="SearchBtn" href="#" class="easyui-linkbutton" onclick="SearchDishes()" data-options="iconCls:'icon-search'">检索</a>
        </div>
    </div>

    <!--修改S-->
    <div id="UpdateBoxDialog" class="easyui-dialog" style="width: 300px; padding: 10px 0" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="edit_form" method="post" novalidate="novalidate">
            <table>
                <tr style="height: 20px">
                    <td class="fr">包厢名称：</td>
                    <td>
                        <input id="e_boxname" class="easyui-textbox" style="width: 150px; height: 20px" data-options="required:true">
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">使用状态：</td>
                    <td>
                        <input id="e_boxstat" class="easyui-combobox" style="width: 150px; height: 20px" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="height: 30px">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
                        <a id="btnUpdate" href="#" onclick="BindEditBoxClickEvent()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存修改</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <!--修改E-->
</body>
</html>
